import axios from 'axios'
import axiosAdapterUniapp from 'axios-adapter-uniapp'

export const request = axios.create({
	timeout: 6000,
	adapter: axiosAdapterUniapp as any,
	// 此处必须使用IP,且不能是127.0.0.1
	baseURL: "http://192.168.3.9:8080",
	// baseURL: "http://192.168.18.219:8080",
})

// request 拦截器
request.interceptors.request.use(
	(config) => {
		// 在这里可以设置请求头、请求参数等return config
		return config
	},
	(error) => {
		// 请求错误处理
		console.log(error)
		return Promise.reject(error)
	},
)

// 响应拦截器
request.interceptors.response.use((response) => {
	return new Promise((resolve, reject) => {
		console.log(response, '======asdas111')
		if (response.data.code === 0 || response.data.code === 200) {
			return resolve(response.data)
		} else {

			return reject(response.data.message)
		}
	})
})